#include "Preprocessor.hpp"
#include "UnicodeConverter.hpp"
bool Level5::Preprocessor::isIdentifier(const std::u32string& str)
{
	for (auto it : str)
	{

	}
	return false;
}
Level5::Preprocessor::Token::Token(std::u16string fileName, size_t line) :
	fileName(UnicodeConverter::ConvertFromUTF16ToUTF32(fileName)),
	line(line),
	row(1),
	type(Type::Nul)
{
}
Level5::Preprocessor::Token::Token(std::u16string fileName, std::u32string value, size_t line, size_t row) :
	fileName(UnicodeConverter::ConvertFromUTF16ToUTF32(fileName)),
	line(line),
	row(row),
	value(value),
	type(Type::Nul)
{
}
Level5::Preprocessor::Token::Token(const Preprocessor* preprocessor) :
	line(preprocessor->line),
	row(preprocessor->row),
	fileName(preprocessor->fileName),
	type(Type::Nul)
{
}
Level5::Preprocessor::Preprocessor() :
	line(1), row(1), inFileSize(0)
{
}
std::list<Level5::Preprocessor::Token>* Level5::Preprocessor::operator()(const char16_t* fileName)
{
	FILE* inF;
	_wfopen_s(&inF, (const wchar_t*)fileName, L"rb");
	if (!inF)
		return nullptr;
	_fseeki64_nolock(inF, 0, SEEK_END);
	inFileSize = _ftelli64_nolock(inF);
	rewind(inF);
	char8_t* p = new char8_t[inFileSize + 8];
	if (!p)
		return nullptr;
	if (fread_s(p, inFileSize + 8, 1, inFileSize, inF) != inFileSize)
	{
		_fclose_nolock(inF);
		return nullptr;
	}
	_fclose_nolock(inF);
	p[inFileSize] = 0;
	inFile = UnicodeConverter::ConvertFromUTF8ToUTF32(p);
	delete[] p;
	this->fileName = UnicodeConverter::ConvertFromUTF16ToUTF32(fileName);
	return new std::list<Level5::Preprocessor::Token>();
}